package com.weitao.marketserver.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动更新字段
 */
@Component
@Slf4j
public class DateHandler implements MetaObjectHandler {

    /**
     * 插入填充
     * @param metaObject 元对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("tmcreate",new Date(),metaObject);
        this.setFieldValByName("tmmodified",new Date(),metaObject);
    }

    /**
     * 更新填充
     * @param metaObject 元对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("tmmodified",new Date(),metaObject);
    }
}
